import Model from "js-model"
import helper from "../../common/helper.js"
const app = getApp()
class Detail extends Model {
	parse(data) {
		let actDetail = super.parse(data)
		if (!helper.isEmpty(actDetail.image_url)) actDetail.image_url = app.globalData.BACK_URL + actDetail.image_url
		if (!helper.isEmpty(actDetail.share_img)) actDetail.share_img = app.globalData.BACK_URL + actDetail.share_img
		if (!helper.isEmpty(actDetail.show_img_url)) actDetail.show_img_url = app.globalData.BACK_URL + actDetail.show_img_url
		if (!helper.isEmpty(actDetail.coupon_num)) actDetail.barcodeurl = app.globalData.BASE_URL + 'Barcode/getBarcode?code=' + actDetail.coupon_num
		if (!helper.isEmpty(actDetail.password)) actDetail.pwdcodeurl = app.globalData.BASE_URL + 'Barcode/getBarcode?code=' + actDetail.password
		
		actDetail.price = parseFloat(actDetail.price)
		actDetail.amount = parseFloat(actDetail.amount)
		actDetail.rebate = parseFloat(actDetail.rebate)
		// 对活动规则进行分割
		actDetail.act_rule = helper.strFormat(actDetail.act_rule)
		actDetail.comp_explain = helper.strFormat(actDetail.comp_explain)
		if (helper.isEmpty(actDetail.text1)) actDetail.text1 = '您好，如果遇到无法用券，请您点击联系客服，我们会在3分钟内答复，谢谢！'
		
		
		return actDetail
	}
	dispose(data, param) {
		return super.dispose(data, param)
	}
}
export default new Detail({
	act_name: String,
	act_num: String,
	act_rule: String,
	all_city: String,
	allow_city: {
		type: Array,
		default: []
	},
	allshop: String,
	amount: Number,
	band_end: String,
	band_explain: String,
	band_start: String,
	barcodeurl: String,
	cartBatchNo: String,
	category: String,
	choice: String,
	comp_explain: String,
	coupon_id: Number,
	coupon_num: String,
	comp_ids: String,
	comp_name: String,
	coupon_type: String,
	createdate: {
		type: Date,
		format: 'YYYY-MM-DD'
	},
	enddate: {
		type: Date,
		format: 'YYYY-MM-DD'
	},
	explain: String,
	id: Number,
	image_url: String,
	instruction: String,
	is_extend: String,
	is_fresh: String,
	is_third: String,
	limit_time: String,
	max_receive_num: Number,
	modifydate: String,
	modifyname: String,
	need_pass: String,
	plan_id: Number,
	plantype: String,
	price: Number,
	password: {
		type: Number,
		default: ''
	},
	pwdcodeurl: String,
	rebate: Number,
	recommend: String,
	recommend_sort: Number,

	share_img: String,
	show_img_url: String,

	sort: Number,
	startdate: {
		type: Date,
		format: 'YYYY-MM-DD'
	},
	status: String,
	stock: Number,
	text1: String,
	text2: String,
	text3: String,
	text4: String,
	time_limit_type: String,
	time_show: String,
	time_type: String,
	use_type: String,
})
